package main

import (
	"natsmicro/conf"
	"strconv"
	"sync"

	"github.com/gogf/gf/util/grand"
	"github.com/nats-io/stan.go"
)

var donewg sync.WaitGroup

func main() {
	ns, err := stan.Connect("test-cluster", "myID3"+grand.Letters(3), stan.NatsURL(conf.NatsUrl))
	println(conf.NatsUrl)

	if err != nil {
		println(err.Error())
		return
	}

	NN := 100000
	donewg.Add(NN)

	for ii := 0; ii < NN; ii++ {
		var jj = ii
		go func() {
			ns.Publish(conf.SubjectNameSub, []byte("Hello World "+strconv.Itoa(jj)))
			// fmt.Println("ii", jj)
			donewg.Done()
		}()
	}
	donewg.Wait()

	ns.Close()
}
